import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import '/util/assets_util.dart';

/// todo: 可点击组件
class InkWidget{

  static Widget text(text,{Color? color,double? fonSize,double? height,FontWeight? fontWeight,Function()? onTap,int? maxLines}){
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap ?? null,
        child: Text("${text ?? ''}",style: TextStyle(height: height,color: color,fontWeight: fontWeight,fontSize: fonSize,),maxLines: maxLines,overflow: TextOverflow.ellipsis,),
      ),
    );
  }

  static Widget title(text,{Color? color,double? fonSize,Function()? onTap,int? maxLines}){
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap ?? null,
        child: Text("${text ?? ''}",style: TextStyle(color: color,fontWeight: FontWeight.bold,fontSize: fonSize,),maxLines: maxLines,overflow: TextOverflow.ellipsis,),
      ),
    );
  }

  static imgAsset(String imgName,{Color? color,EdgeInsetsGeometry? padding,double? width,double? height,Function()? onTap,BoxFit? fit}){
    return Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onTap ?? null,
          child: Padding(
              padding: padding ?? EdgeInsets.all(0),
              child:Image.asset(getLocalImg("$imgName"),color: color ,width: width,height: height,fit: fit,),
          ),
        ),
      );
  }

  static imgNet(String imgHostUrl,{EdgeInsetsGeometry? padding,double? width,double? height,bool size:false,bool clip:false,Function()? onTap,BoxFit? fit,BorderRadius? borderRadius}){
    return Padding(
      padding: padding ?? EdgeInsets.all(0),
      child: ClipRRect(
        borderRadius: borderRadius ?? BorderRadius.circular(clip ? width?? 0 : 0) ,
        child: Container(
          child: InkWell(
            onTap: onTap ?? null,
            child: CachedNetworkImage(
              imageUrl: imgHostUrl,width: width,height: size ? width:height,fit: fit ?? BoxFit.cover,
              progressIndicatorBuilder: (ctx,a,b){
                return Center(child: CircularProgressIndicator(),);
              },
              errorWidget: (ctx,url,err)  {
                return Center(
                  child: Icon(Icons.error),
                );
              },
            ),
            // child: Image.network(imgHostUrl,width: width,height: height,fit: fit ?? BoxFit.cover,),
          ),
        ),
      ),
    );
  }

}